extends Control

#节点加载---start
@onready var label = $majiangkuai/Label
@onready var mahjong_animated = $majiangkuai
@onready var mahjong_img = $majiangkuai/MahjongImg
#节点加载---end

@export var mahjong_type: String = ""
@export var mahjong_id: String = ""

# 对照表
var typeToChinese = {
	"wan_1": "一万", "wan_2": "二万", "wan_3": "三万", "wan_4": "四万", "wan_5": "五万", "wan_6": "六万", "wan_7": "七万", "wan_8": "八万", "wan_9": "九万",
	"tong_1": "一筒", "tong_2": "二筒", "tong_3": "三筒", "tong_4": "四筒", "tong_5": "五筒", "tong_6": "六筒", "tong_7": "七筒", "tong_8": "八筒", "tong_9": "九筒",
	"tiao_1": "一条", "tiao_2": "二条", "tiao_3": "三条", "tiao_4": "四条", "tiao_5": "五条", "tiao_6": "六条", "tiao_7": "七条", "tiao_8": "八条", "tiao_9": "九条",
	"dong_1": "东风", "nan_1": "南风", "xi_1": "西风", "bei_1": "北风", "hongzhong_1": "红中", "facai_1": "发财", "baiban_1": "白板"
}

var parentGameProgress
var new_texture

func _ready() -> void:
	label.text = mahjong_type[0] + "\n" + mahjong_type[1]
	var mahjongId = mahjong_id.split("_")[0] + "_" + mahjong_id.split("_")[1]
	var imgPathStr = "res://Resources/Img/Mahjongs/" + mahjongId +".png"
	new_texture = load(imgPathStr)
	var parent = get_parent()  # 获取父节点
	if parent:
		var grandParent = parent.get_parent()  # 获取父节点的父节点（即祖父节点）
		parentGameProgress = grandParent.gameProgress #获取游戏进程
		if parentGameProgress == 1:
			mahjong_animated.play()
		else:
			pass
			#label.visible = true
	
func _process(delta):
	if mahjong_animated.frame == 3:
		if new_texture:
			mahjong_img.visible = true
			mahjong_img.texture = new_texture
		else:
			pass
			#label.visible = true
